﻿using System.IO;
using UnityEditor;
using UnityEngine;

namespace ZyGame.Editor.Process
{
    internal class CreateGameObjectMaterialProcess
    {
        public static void Running()
        {
            if (Selection.objects == null)
            {
                EditorUtility.DisplayDialog("Tips", "Please select a object", "OK");
                return;
            }

            for (int i = 0; i < Selection.objects.Length; i++)
            {
                if (Selection.objects[i] is not Texture)
                {
                    continue;
                }

                Material material = new Material(Shader.Find("Unlit/Texture"));
                material.mainTexture = (Texture)Selection.objects[i];
                string path = AssetDatabase.GetAssetPath(Selection.objects[i]);
                AssetDatabase.CreateAsset(material, Path.GetDirectoryName(path) + "/" + Path.GetFileNameWithoutExtension(path) + ".mat");
            }
        }
    }
}
